/* eslint-disable import/namespace */
/* eslint-disable @typescript-eslint/no-namespace */
"use strict";

// "tooling": "github:webpack/tooling",
// import {} from "tooling";

import cli = require("@rspack/cli");

import type * as Rspack from "@rspack/core";
import { type SameShape } from "esbuild";
import type * as Webpack from "webpack";
// const { registerLoader } = require("webpack").util.serialization;

namespace webpackTool {
  export function defineConfig<T extends Webpack.Configuration>(
    config: T,
  ): SameShape<Webpack.Configuration, T> {
    return config as SameShape<Webpack.Configuration, T>;
  }
  /**
   * @template {import("webpack").WebpackPluginInstance} T
   * @param {object} plugin
   * @returns {T}
   */
  export function definePlugin<T extends Webpack.WebpackPluginInstance>(
    plugin: T,
  ): T {
    return plugin;
  }

  /**
   * @template {NonNullable<import("webpack").Configuration['module']>['rules']} T
   * @param {unknown} rule
   * @returns {T}
   */
  export function defineLoaderRuleSet<T extends Webpack.RuleSetRule>(
    rule: T,
  ): T {
    return rule;
  }
}
namespace rspackTool {
  export const { defineConfig, definePlugin } = cli;
  export function defineLoaderRuleSet<T extends Rspack.RuleSetRule>(
    config: T,
  ): SameShape<Rspack.RuleSetRule, T> {
    return config as SameShape<Rspack.RuleSetRule, T>;
  }
}

export = {
  webpackTool,
  rspackTool,
};
